#include "CocosPCH.h"
#include "StudioViewer.h"

bool StudioViewer::initUI()
{
    BaseViewer::initUI();

    m_strMaskTextureFormat = CCUserDefault::getInstance()->getStringForKey("MaskTextureFormat", "{1%s}_alpha{2%s}");

    return true;
}
StudioViewer::StudioViewer()
{
    //m_bHasExportOne = true;
    //m_bHasExportAll = true;
}

ui::Widget* StudioViewer::createItem(int nIndex, std::string strName)
{
    auto button = ui::Button::create("Button_Normal.png");
    button->setContentSize(Size(104, 40));
    button->setScale9Enabled(true);
    button->setTitleText(strName);
    button->setTitleFontSize(15);
    button->setTitleColor(Color3B(0, 0, 0));

    return button;
}

void StudioViewer::Export(std::string strPath)
{
    Data data = FileUtils::getInstance()->getDataFromFile(strPath);
    std::string strToDir = strPath + ".Image\\";
    Utility_ConvertUtf8ToGBK(strToDir);
    Utility_ExportImageFromPlist((const char*)data.getBytes(), strToDir.c_str());
}

bool StudioViewer::LoadFile(std::string strPath)
{
    BaseViewer::LoadFile(strPath);
    Node *pContent = CSLoader::createNode(strPath);
    //ui::Widget *pContent = GUIReader::shareReader()->widgetFromBinaryFile(strPath.c_str());
    Size size = pContent->getContentSize();
    Size viewSize = getContentSize();

    float fScaleX = viewSize.width / size.width;
    float fScaleY = viewSize.height / size.height;
    float fScale = std::min(fScaleX, fScaleY);
    pContent->setScale(fScale);
    pContent->setScale(0.4f);
    //pContent->setPosition(0);

    m_pViewNode->addChild(pContent);

    return true;
}

void StudioViewer::ClearCache()
{
}